package com.igeek.boot.controller;

import com.igeek.boot.result.Result;
import com.igeek.boot.utils.QiniuUtils;
import com.igeek.boot.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * @package com.igeek.boot.controller
 * @Description 七牛云的文件上传测试
 * @Author LittlePunk [296526219@qq.ccom]
 * @Version 2022.1
 * @Date 2023/12/30 18:18
 */
@RestController
@RequestMapping("/wisdom_factory/qiniu")
@Api(tags = "套餐接口")
@Slf4j
public class QINiuTestController {



    @Autowired
    private RedisUtils redisUtils;
    //文件上传测试
    @ApiOperation("上传套餐图片")
    @PostMapping("upload")
    public Result upload(@RequestPart("imgFile") MultipartFile imgFile) throws IOException {
        if(imgFile!=null){
            String oldName = imgFile.getOriginalFilename();
            if(StringUtils.hasLength(oldName)){
                String newName = UUID.randomUUID()+oldName.substring(oldName.lastIndexOf("."));
                //七牛云上传图片
                String img = QiniuUtils.uploadForQiniu(imgFile.getInputStream(), newName);
                return new Result(true , "上传成功");
            }
        }
        return new Result(true , "上传成功");
    }
}
